package com.yunxi.controller.finance;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.finance.pojo.DynamicRebateCommissionAuditReqVO;
import com.yunxi.finance.pojo.DynamicRebateCommissionImportReqVO;
import com.yunxi.finance.pojo.DynamicRebateCommissionQueryReqVO;
import com.yunxi.finance.pojo.KeepAccountsReqVO;
import com.yunxi.finance.service.DynamicRebateCommissionDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 返利与佣金 前端控制器
 * </p>
 *
 * @author 
 * @since 2019-09-16
 */
@RestController
@RequestMapping("/admin/dynamicrebatecommission")
@Api(tags = "pms:dynamicrebatecommission", description = "返利与佣金接口")
public class DynamicRebateCommissionController {
    private static final Logger logger = LoggerFactory.getLogger(DynamicRebateCommissionController.class);

     @Autowired
     DynamicRebateCommissionDubboService dynamicRebateCommissionDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询返利与佣金分页")
    public ApiResult page(DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO, Integer pageNum, Integer pageSize) throws Exception {
       return ResponseUtil.ok(dynamicRebateCommissionDubboService.findPageByVO(dynamicRebateCommissionVO,pageNum,pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询返利与佣金列表")
    public ApiResult list(DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO) throws Exception {
      return ResponseUtil.ok(dynamicRebateCommissionDubboService.listByVo(dynamicRebateCommissionVO));
    }

     @PostMapping("/save")
     @ApiOperation(value = "保存返利与佣金信息")
     public ApiResult save(@RequestBody DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO, @CurrentUser LoginInfo loginInfo) throws Exception {
         dynamicRebateCommissionDubboService.save(dynamicRebateCommissionVO);
          return ResponseUtil.ok("success");
     }

     @PostMapping("/del")
     @ApiOperation(value = "删除返利与佣金")
     public ApiResult del(@RequestBody List<DynamicRebateCommissionQueryReqVO> dynamicRebateCommissionVOList) throws Exception {
         dynamicRebateCommissionDubboService.removeByListVo(dynamicRebateCommissionVOList);
          return ResponseUtil.ok("success");
     }

    @GetMapping("/queryDynamicRebateCommissionByList")
    @ApiOperation(value = "查询返利与佣金分页")
    public ApiResult queryDynamicRebateCommissionByList(DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO, Integer pageNum, Integer pageSize){
       return ResponseUtil.ok(dynamicRebateCommissionDubboService.queryDynamicRebateCommissionByList(dynamicRebateCommissionVO,pageNum,pageSize));
    }

    @GetMapping("/queryDynamicRabateCommissionBySingle")
    @ApiOperation(value = "读取单个返利与佣金")
    public ApiResult queryDynamicRabateCommissionBySingle(DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(dynamicRebateCommissionDubboService.queryDynamicRabateCommissionBySingle(dynamicRebateCommissionVO));
    }

    @PostMapping("/audit")
    @ApiOperation(value="审核")
    public ApiResult audit(@RequestBody DynamicRebateCommissionAuditReqVO vo){
        return ResponseUtil.ok(dynamicRebateCommissionDubboService.audit(vo));
    }

    @PostMapping("/export")
    @ApiOperation(value = "导出excel")
    public ApiResult export(@RequestBody(required=false) DynamicRebateCommissionQueryReqVO dynamicRebateCommissionVO) {
       return ResponseUtil.ok(dynamicRebateCommissionDubboService.exportData(dynamicRebateCommissionVO));
    }

    @GetMapping("/keepAccounts")
    @ApiOperation(value = "返利")
    public ApiResult keepAccounts(String orderNo){
        return ResponseUtil.ok(dynamicRebateCommissionDubboService.keepAccounts(orderNo));
    }

    @PostMapping("/importData")
    public ApiResult importData(@RequestBody DynamicRebateCommissionImportReqVO vo){
         return dynamicRebateCommissionDubboService.importData(vo);
    }

    @GetMapping("/rebateForZiYouZiJin")
    @ApiOperation(value = "返利")
    public ApiResult rebateForZiYouZiJin(String orderNo){
        dynamicRebateCommissionDubboService.rebateForZiYouZiJin(orderNo);
        return ResponseUtil.ok();
    }
}
